<?php
	$session = Mage::getSingleton('checkout/session');
	$lass_order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
	$model = Mage::getModel('enets/method_enets');
	// $quote = Mage::getModel('checkout/session')->getQuote();
	// $total = $quote->getGrandTotal();
	$enets_mid = $model->getConfigData('nets_mid');
	$merchant_cert_id = $model->getConfigData('merchant_cert_id');
	$currency =  Mage::app()->getStore()->getCurrentCurrencyCode();
	$order = Mage::getSingleton('sales/order');
	$order->loadByIncrementId($lass_order_id);
	$_totalData = $order->getSubtotal();
	$_grand = $_totalData['grand_total'];
	//print_r( $_totalData );
	
	//set POST variables
		//$url = 'https://test.enets.sg/enets2/PaymentListener.do';
		$url = 'http://enets.gobblershop.com/gs/cc_browser_request02.aspx';
		$fields = array(
			'nets_mid'		  		=>$enets_mid,
			'submission_mode'		=>'B',
			'txn_amount'			=>round ($_totalData, 2)*100,
			'merchant_txn_ref'		=>$lass_order_id,
			'merchant_cert_id'		=>$merchant_cert_id,
			'payment_mode'			=>'CC',
			'currency_code'			=>$currency,			
			'payment_type'			=>'SALE',									
			'success_url'			=>'http://enets.gobblershop.com/gs/cc_browser_success.aspx',			
			'success_url_params'	=>'order_id=' . $lass_order_id,			
			'failure_url'			=>'http://enets.gobblershop.com/gs/cc_browser_success.aspx',			
			'failure_url_params'	=>'order_id=' . $lass_order_id,			
			'cancel_url'			=>'http://enets.gobblershop.com/gs/cc_browser_success.aspx',			
			'cancel_url_params'		=>'order_id=' . $lass_order_id,			
		);

		//url-ify the data for the POST
		// foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
		// rtrim($fields_string,'&');

		// //open connection
		// $ch = curl_init();

		// //set the url, number of POST vars, POST data
		// curl_setopt($ch,CURLOPT_URL,$url);
		// curl_setopt($ch,CURLOPT_POST,count($fields));
		// curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

		// //execute post
		// $result = curl_exec($ch);

		// //close connection
		// curl_close($ch);
		
?>
<img src="<?php echo $this->getSkinUrl('images/Gobbler_960banner.jpg') ?>" width="100%" height="100%"/>
<!--http://enets.gobblershop.com/gs/cc_browser_request.aspx-->
<form name="cart" method="post" action="http://enets.gobblershop.com/gs/cc_browser_request02.aspx" style="left: -9999px;top:-9999px;position: relative;z-index:-999999;opacity:0;">
	<input type="hidden" name="nets_mid" value="<?php echo $enets_mid ?>">
	<input type="hidden" name="submission_mode" value="B">
	<input type="hidden" name="txn_amount" value="<?php echo round ($_totalData, 2)*100?>">
	<input type="hidden" name="merchant_txn_ref" value="<?php echo $lass_order_id?>">
	<input type="hidden" name="merchant_cert_id" value="<?php echo $merchant_cert_id ?>">
	<input type="hidden" name="currency_code" value="<?php echo $currency?>"/>
	<input type="hidden" name="payment_type" value="SALE">
	<input type="hidden" name="payment_mode" value="CC">
	<input type="hidden" name="success_url" value="http://enets.gobblershop.com/gs/cc_browser_success.aspx">
	<input type="hidden" name="success_url_params" value="order_id=<?php echo $lass_order_id ?>">
	<input type="hidden" name="failure_url" value="http://enets.gobblershop.com/gs/cc_browser_success.aspx">
	<input type="hidden" name="failure_url_params" value="order_id=<?php echo $lass_order_id ?>">
	<input type="hidden" name="cancel_url" value="http://enets.gobblershop.com/gs/cc_browser_success.aspx">
	<input type="hidden" name="cancel_url_params" value="order_id=<?php echo $lass_order_id ?>">
	<input type="hidden" name="status" value="Y">
	<input type="submit" id="submit">
</form>
<script type="text/javascript">
    //<![CDATA[
	jQuery(document).ready(function(){
		 jQuery('#submit').click();
	});
    // jQuery.ajax({
	  // url: 'http://enets.gobblershop.com/gs/cc_browser_request02.aspx',
	  // type: "POST",
	  // data:"nets_mid='<?php echo $enets_mid ?>'&submission_mode=B&txn_amount='<?php echo round ($_totalData, 2)*100?>'&merchant_txn_ref='<?php echo $lass_order_id?>'&merchant_cert_id='<?php echo $merchant_cert_id ?>'&currency_code='<?php echo $currency?>'&payment_type='CC'&success_url='http://enets.gobblershop.com/gs/cc_browser_success.aspx'&success_url_params='order_id=<?php echo $lass_order_id ?>'&failure_url='http://enets.gobblershop.com/gs/cc_browser_success.aspx'&failure_url_params='order_id=<?php echo $lass_order_id ?>'&cancel_url='http://enets.gobblershop.com/gs/cc_browser_success.aspx'&cancel_url_params='order_id=<?php echo $lass_order_id ?>'",
	  // success: function(data) {
		// console.log(data);
		// //alert('Load was performed.');
	  // }
	// });
    //]]>
</script>